package cn.edu.sgu.www.mhxysy.controller.chongwu;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.chongwu.ChongwuJiadianDTO;
import cn.edu.sgu.www.mhxysy.dto.chongwu.ChongwuJiadianRenameDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu.ChongwuJiadian;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.chongwu.ChongwuJiadianService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "宠物加点管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/chongwu_jiadian", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChongwuJiadianController {

	private final ChongwuJiadianService chongwuJiadianService;

	@Autowired
	public ChongwuJiadianController(ChongwuJiadianService chongwuJiadianService) {
		this.chongwuJiadianService = chongwuJiadianService;
	}

	@ApiOperation("重命名加点方案")
	@RequestMapping(value = "/rename", method = RequestMethod.POST)
	public JsonResult<Void> rename(@Validated ChongwuJiadianRenameDTO chongwuJiadianRenameDTO) {
		chongwuJiadianService.rename(chongwuJiadianRenameDTO);

		return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
	}

	@ApiOperation("解锁加点方案")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "chongwuId", value = "宠物ID", required = true),
			@ApiImplicitParam(name = "jiadianSchema", value = "加点方案", required = true)
	})
	@RequestMapping(value = "/unlock", method = RequestMethod.POST)
	public JsonResult<Void> unlock(
			@NotBlank(message = "宠物ID不能为空") String chongwuId,
			@NotNull(message = "加点方案不能为空") Integer jiadianSchema) {
		chongwuJiadianService.unlock(chongwuId, jiadianSchema);

		return JsonResult.success("成功解锁第" + jiadianSchema + "套加点方案.");
	}

	@ApiOperation("修改宠物加点和属性信息")
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public JsonResult<Void> update(@Validated ChongwuJiadianDTO chongwuJiadianDTO) {
		chongwuJiadianService.update(chongwuJiadianDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("通过宠物ID和加点方案查询宠物加点")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "chongwuId", value = "宠物ID", required = true),
			@ApiImplicitParam(name = "jiadianSchema", value = "加点方案", required = true)
	})
	@RequestMapping(value = "/selectJiadian", method = RequestMethod.GET)
	public JsonResult<ChongwuJiadian> selectJiadian(
			@NotBlank(message = CustomMessages.CHONGWU_ID_NOT_NULL) String chongwuId,
			@NotNull(message = "加点方案" + CustomMessages.NOT_NULL) Integer jiadianSchema) {
		ChongwuJiadian chongwuJiadian = chongwuJiadianService.selectJiadian(chongwuId, jiadianSchema);

		return JsonResult.success(null, chongwuJiadian);
	}

}